MogileFS分布式文件系统
==============================================

一：简介

1：获取地址
    github地址：https://github.com/mogilefs
    官网：http://www.mogilefs.org

http://search.cpan.org/dist/ExtUtils-MakeMaker/

yum -y install perl-devel libyaml libyaml-devel perl-YAML.noarch perl-YAML-LibYAML perl-YAML-Syck perl-YAML-Tiny.noarch gcc gcc-c++
yum -y install cpan



perl-YAML.noarch : YAML Ain't Markup Language (tm)
perl-YAML-LibYAML.x86_64 : Perl YAML Serialization using XS and libyaml
perl-YAML-Syck.x86_64 : Fast, lightweight YAML loader and dumper
perl-YAML-Tiny.noarch






http://www.jb51.net/article/56286.htm
http://wenku.baidu.com/link?url=dBPWzLvBLBvf8vmK4_YiNoad95BdRVySXMeJytQLX1bfcCJ4RQ_TELLrdjDeqhJTAg9vUvII-TpipHmrGdgcxLrLxVlIjEUCPKMvTtMP1Sy





Domain


应用层：运行于用户控件
无单点：
    Mogstored：存储多个数据副本
    Tracker：多节点
    Database：MySQL
自动文件复制
传输中立，无特殊协议


www.cpan.org



构建方式：
    1：






172.18.21.60
172.18.21.61
172.18.21.40


MogileFS-Server-2.46-2.el6.noarch.rpm
MogileFS-Server-mogilefsd-2.46-2.el6.noarch.rpm
MogileFS-Server-mogstored-2.46-2.el6.noarch.rpm
MogileFS-Utils-2.19-1.el6.noarch.rpm
perl-Danga-Socket-1.61-1.el6.rf.noarch.rpm
perl-IO-stringy-2.110-1.2.el6.rfx.noarch.rpm
perl-MogileFS-Client-1.14-1.el6.noarch.rpm
perl-Net-Netmask-1.9015-8.el6.noarch.rpm
perl-Perlbal-1.78-1.el6.noarch.rpm

~]# yum -y install *.rpm
~]# yum -y install perl-IO-AIO

~]# /etc/mogilefs/mogilefsd.conf
db_dsn = DBI:mysql:mogilefs:host=172.18.21.40
db_user = root
db_pass = 123456
listen = 0.0.0.0:7001

# mogilefs 是 数据库名 

~]# mogdbsetup -h
~]# mogdbsetup --dbhost=172.18.21.40 --dbname=mogilefs  --dbrootuser=root  --dbrootpass=123456  --dbuser=root  --dbpass=123456

MariaDB [(none)]> use mogilefs;
Database changed
MariaDB [mogilefs]> show tables;
+----------------------+
| Tables_in_mogilefs   |
+----------------------+
| checksum             |
| class                |
| device               |
| domain               |
| file                 |
| file_on              |
| file_on_corrupt      |
| file_to_delete       |
| file_to_delete2      |
| file_to_delete_later |
| file_to_queue        |
| file_to_replicate    |
| fsck_log             |
| host                 |
| server_settings      |
| tempfile             |
| unreachable_fids     |
+----------------------+



~]# service mogilefsd start





~]# /etc/mogilefs/mogstored.conf
~]# mkdir /var/mogdata
~]# chown mogilefs:mogilefs /var/mogdata/
~]# mkdir /var/mogdata/dev{1,2}

~]# service mogstored start



~]# mogstats --help

~]# ]# mogstats --db_dsn="DBI:mysql:mogilefs:host=172.18.21.40" --db_user="root" --db_pass="123456" --stats="all"




[root@localhost source]# mogadm --help
Usage:  (enter any command prefix, leaving off options, for further help)

  mogadm check                     Check the state of the MogileFS world.
  mogadm stats                     Show MogileFS system statistics.  (DEPRECATED: use mogstats instead)
  mogadm host ...
         host add ...              Add a host to MogileFS.
         host delete ...           Delete a host.
         host list                 List all hosts.
         host mark ...             Change the status of a host.  (equivalent to 'modify --status')
         host modify ...           Modify a host's properties.
  mogadm device ...
         device add ...            Add a device to a host.
         device list ...           List all devices, for each host.
         device mark ...           Mark a device as {alive,dead,down,drain,readonly}
         device modify ...         Modify a device's properties.
         device summary ...        List the summary of devices, for each host.
  mogadm domain ...
         domain add ...            Add a domain (namespace)
         domain delete ...         Delete a domain.
         domain list               List all hosts.
  mogadm class ...
         class add ...             Add a file class to a domain.
         class delete ...          Delete a file class from a domain.
         class list                List all classes, for each domain.
         class modify ...          Modify properties of a file class.


host
~]# mogadm host add --help
~]# mogadm host add 172.18.21.60 --ip=172.18.21.60 --port=7500 --status=alive
~]# mogadm host add 172.18.21.61 --ip=172.18.21.61 --port=7500 --status=alive
[root@localhost source]# mogadm host list
172.18.21.60 [1]: alive
  IP:       172.18.21.60:7500
172.18.21.61 [2]: alive
  IP:       172.18.21.61:7500

device
~]# mogadm device --help
~]# mogadm device add 172.18.21.60 1
~]# mogadm device add 172.18.21.60 2
~]# mogadm device add 172.18.21.61 3
~]# mogadm device add 172.18.21.61 4
~]# mogadm device list
172.18.21.60 [1]: alive
                    used(G)    free(G)   total(G)  weight(%)
   dev1:   alive      0.794     45.796     46.590        100
   dev2:   alive      0.794     45.796     46.590        100

172.18.21.61 [2]: alive
                    used(G)    free(G)   total(G)  weight(%)
   dev3:   alive      0.760     45.830     46.590        100
   dev4:   alive      0.760     45.830     46.590        100




domain
~]# mogadm domain --help
~]# mogadm domain add files
~]# mogadm domain add imgs
~]# mogadm domain list
 domain               class                mindevcount   replpolicy   hashtype
-------------------- -------------------- ------------- ------------ -------
 files                default                   2        MultipleHosts() NONE   

 imgs                 default                   2        MultipleHosts() NONE   



class
~]# mogadm class list
 domain               class                mindevcount   replpolicy   hashtype
-------------------- -------------------- ------------- ------------ -------
 files                default                   2        MultipleHosts() NONE   

 imgs                 default                   2        MultipleHosts() NONE   

[root@localhost mogdata]# 



文件上传：
~]# mogupload --help
~]#  mogupload --trackers=172.18.21.60 --domain=files --key='/fstab.txt' --file='/etc/fstab'

文件查看：
~]# moglistkeys --help
~]# moglistkeys --trackers=172.18.21.60 --domain=files

下载：
~]# mogfetch --trackers=172.18.21.60 --domain=files --key='/fstab.txt' --file='/tmp/fstab'
备注：一般使用 php 扩展mogilefs 下载文件。

查看信息：
~]# mogfileinfo --help
~]# mogfileinfo --trackers=172.18.21.60 --domain=files --key='/fstab.txt'
- file: /fstab.txt
     class:              default
  devcount:                    2
    domain:                files
       fid:                    4
       key:           /fstab.txt
    length:                  860
 - http://172.18.21.60:7500/dev1/0/000/000/0000000004.fid
 - http://172.18.21.61:7500/dev4/0/000/000/0000000004.fid

# 备注： 可以根据http地址直接查看




nginx 模块反代（重新编译nginx）
准备：nginx 和 nginx_mogilefs_module 包
nginx_mogilefs_module 包可以从nginx 官网获取
示例：http://www.grid.net.ru/nginx/mogilefs.en.html

./configure --prefix=/usr/local/nginx --conf-path=/etc/nginx/nginx.conf --user=nginx --group=nginx --add-module=../nginx_mogilefs_module-1.0.4



location /imgs/ {
    mogilefs_tracker 172.18.21.60:7001;
    mogilefs_domain imgs;

    mogilefs_pass {
        proxy_pass $mogilefs_path;
        proxy_hide_header Content-Type;
        proxy_buffering off;
    }
}


上传一个文件：
mogupload --trackers=172.18.21.60 --domain=imgs --key='a.jpg' --file='/usr/share/backgrounds/centos_1920x1200_logoonly.jpg'

浏览器访问：
http://172.18.21.60/imgs/a.jpg


并且支持负载均衡

upstream示例：
    upstream mogilefs {
        server 172.18.21.60:7001;
        server 172.18.21.61:7001;
    }

location /imgs/ {
    mogilefs_tracker mogilefs;
    mogilefs_domain imgs;

    mogilefs_pass {
        proxy_pass $mogilefs_path;
        proxy_hide_header Content-Type;
        proxy_buffering off;
    }
}




location /upload/ {
    allow 192.168.2.0/24;
    deny all;

    mogilefs_tracker 192.168.2.2;
    mogilefs_domain example_domain;
    mogilefs_methods PUT DELETE;

    mogilefs_pass {
        proxy_pass $mogilefs_path;
        proxy_hide_header Content-Type;
        proxy_buffering off;
    }
}













==============================================
gslb：全局负载均衡器
slb：本地负载均衡器


zookeoper，etcd
paxes协议：
rpc：远程过程调用



搜索引擎：luser

Domain



































































































